<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>银行客户注册</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background-image: url("../R-C.jpg");
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 900px;
            display: flex;
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
            border-radius: 12px;
            overflow: hidden;
        }

        .illustration {
            width: 40%;
            background: linear-gradient(to bottom right, #1a3a6c, #2c5a8d);
            padding: 40px;
            color: white;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .illustration h2 {
            font-size: 28px;
            margin-bottom: 25px;
            font-weight: 600;
        }

        .illustration p {
            font-size: 16px;
            line-height: 1.7;
            margin-bottom: 30px;
        }

        .features {
            margin-top: 30px;
        }

        .feature-item {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .feature-item i {
            font-size: 22px;
            margin-right: 15px;
            color: #ffcc00;
        }

        .feature-item span {
            font-size: 15px;
        }

        .registration-form {
            width: 60%;
            background-color: white;
            padding: 50px;
        }

        .form-header {
            margin-bottom: 40px;
            text-align: center;
        }

        .form-header h2 {
            color: #2a5298;
            font-size: 28px;
            margin-bottom: 10px;
        }

        .form-header p {
            color: #666;
            font-size: 15px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #444;
            font-size: 15px;
        }

        .form-group input, .form-group textarea {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        .form-group input:focus, .form-group textarea:focus {
            border-color: #2a5298;
            box-shadow: 0 0 0 3px rgba(42, 82, 152, 0.1);
            outline: none;
        }

        .security-info {
            display: flex;
            align-items: center;
            background-color: #f8f9fc;
            border-radius: 8px;
            padding: 15px;
            margin-top: 10px;
        }

        .security-info i {
            font-size: 24px;
            color: #4CAF50;
            margin-right: 15px;
        }

        .security-text {
            font-size: 13px;
            color: #555;
            line-height: 1.5;
        }

        .form-footer {
            margin-top: 25px;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }

        .btn-register {
            padding: 14px;
            background: linear-gradient(135deg, #2a5298, #1e3c72);
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            letter-spacing: 1px;
            position: relative;
            overflow: hidden;
        }

        .btn-register:hover {
            background: linear-gradient(135deg, #1e3c72, #2a5298);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(42, 82, 152, 0.3);
        }

        .btn-register:active {
            transform: translateY(0);
        }

        .login-link {
            text-align: center;
            font-size: 15px;
            color: #666;
        }

        .login-link a {
            color: #2a5298;
            text-decoration: none;
            font-weight: 600;
        }

        .login-link a:hover {
            text-decoration: underline;
        }

        .form-footer .terms {
            display: flex;
            align-items: center;
            font-size: 13px;
            color: #666;
            margin-bottom: 10px;
        }

        .form-footer .terms input {
            width: auto;
            margin-right: 10px;
        }

        .required {
            color: #e74c3c;
            margin-left: 4px;
        }

        .debug-console {
            margin-top: 20px;
            padding: 15px;
            background-color: #f8f9fc;
            border-radius: 8px;
            border: 1px solid #e0e0e0;
            font-family: monospace;
            font-size: 14px;
            max-height: 200px;
            overflow-y: auto;
        }

        .debug-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }

        .debug-title {
            font-weight: 600;
            color: #2a5298;
        }

        .debug-btn {
            background: none;
            border: none;
            color: #666;
            cursor: pointer;
        }

        .debug-btn:hover {
            color: #2a5298;
        }

        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 25px;
            border-radius: 6px;
            color: white;
            font-weight: 500;
            box-shadow: 0 5px 15px rgba(0,0,0,0.15);
            z-index: 1000;
            transform: translateX(150%);
            transition: transform 0.4s ease;
        }

        .notification.show {
            transform: translateX(0);
        }

        .notification.success {
            background: linear-gradient(135deg, #4CAF50, #2E7D32);
        }

        .notification.error {
            background: linear-gradient(135deg, #f44336, #c62828);
        }

        .loader {
            display: inline-block;
            border: 2px solid rgba(255,255,255,0.3);
            border-top: 2px solid #fff;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            animation: spin 1s linear infinite;
            margin-right: 10px;
            vertical-align: middle;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                flex-direction: column;
            }

            .illustration, .registration-form {
                width: 100%;
            }

            .illustration {
                padding: 30px;
            }

            .registration-form {
                padding: 30px;
            }
        }

        @media (max-width: 480px) {
            .illustration {
                padding: 20px;
            }

            .registration-form {
                padding: 25px;
            }

            .form-header h2 {
                font-size: 24px;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .container {
            animation: fadeIn 0.8s ease-out;
        }

        .debug-console {
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="illustration">
            <h2><i class="fas fa-university"></i> 银行客户注册</h2>
            <p>欢迎注册成为我们的尊贵客户，享受便捷的银行服务和安全可靠的金融解决方案。</p>

            <div class="features">
                <div class="feature-item">
                    <i class="fas fa-shield-alt"></i>
                    <span>银行级安全保障技术</span>
                </div>
                <div class="feature-item">
                    <i class="fas fa-credit-card"></i>
                    <span>专属信用卡与储蓄账户</span>
                </div>
                <div class="feature-item">
                    <i class="fas fa-percent"></i>
                    <span>优惠贷款与理财利率</span>
                </div>
                <div class="feature-item">
                    <i class="fas fa-headset"></i>
                    <span>7×24小时专业客户服务</span>
                </div>
            </div>
        </div>

        <div class="registration-form">
            <div class="form-header">
                <h2>创建新账户</h2>
                <p>请填写真实信息完成注册，带<span class="required">*</span>为必填项</p>
            </div>

            <form id="registrationForm">
                <div class="form-group">
                    <label for="CustomerName">客户姓名 <span class="required">*</span></label>
                    <input type="text" id="CustomerName" name="CustomerName" placeholder="请输入您的全名" required>
                </div>

                <div class="form-group">
                    <label for="Pid">身份证号 <span class="required">*</span></label>
                    <input type="text" id="Pid" name="Pid" placeholder="请输入18位身份证号码" maxlength="18" required>
                    <div class="security-info">
                        <i class="fas fa-lock"></i>
                        <div class="security-text">您的身份信息将被严格加密保护，仅用于银行开户验证。</div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="Telephone">手机号码 <span class="required">*</span></label>
                    <input type="tel" id="Telephone" name="Telephone" placeholder="请输入您的手机号码" required>
                </div>

                <div class="form-group">
                    <label for="Address">联系地址 <span class="required">*</span></label>
                    <textarea id="Address" name="Address" placeholder="请输入详细地址（街道、门牌号等）" rows="3" required></textarea>
                </div>

                <div class="form-footer">
                    <div class="terms">
                        <input type="checkbox" id="terms" name="terms" required>
                        <label for="terms">我已阅读并同意《银行服务协议》和《隐私政策》</label>
                    </div>

                    <button type="submit" class="btn-register" id="submitBtn">
                        <span class="loader" id="loader" style="display:none;"></span>
                        <i class="fas fa-user-plus"></i> 立即注册
                    </button>

                    <div class="login-link">
                        已有账户？ <a href="../login.html"><i class="fas fa-sign-in-alt"></i> 立即登录</a>
                    </div>
                </div>
            </form>
            <div class="debug-console">
                            <div class="debug-header">
                                <div class="debug-title">请求调试信息</div>
                                <button class="debug-btn" id="clearDebug"><i class="fas fa-trash"></i> 清空</button>
                            </div>
                            <div id="debugOutput">尚未发送任何请求...</div>
                        </div>
                    </div>
                </div>
        </div>
    </div>

    <div class="notification" id="notification"></div>

    <script>
        // 显示通知函数
        function showNotification(message, isSuccess) {
            const notification = document.getElementById('notification');
            notification.textContent = message;
            notification.className = `notification ${isSuccess ? 'success' : 'error'}`;
            notification.classList.add('show');

            setTimeout(() => {
                notification.classList.remove('show');
            }, 3000);
        }

        // 调试日志函数
        function debugLog(message) {
            const debugOutput = document.getElementById('debugOutput');
            const timestamp = new Date().toLocaleTimeString();
            debugOutput.innerHTML += `<div>[${timestamp}] ${message}</div>`;
            debugOutput.scrollTop = debugOutput.scrollHeight;
        }

        // 清空调试日志
        document.getElementById('clearDebug').addEventListener('click', function() {
            document.getElementById('debugOutput').innerHTML = '日志已清空';
        });

        // 验证身份证格式
        function validateIdCard(id) {
            id = id.trim().toUpperCase();
            if(id.length !== 18) return false;
            return /^\d{17}[\dX]$/.test(id);
        }

        // 验证手机号格式
        function validatePhone(phone) {
            return /^1[3-9]\d{9}$/.test(phone);
        }

        // 表单提交处理
        document.getElementById('registrationForm').addEventListener('submit', async function(e) {
            e.preventDefault();

            // 获取表单元素
            const customerName = document.getElementById('CustomerName');
            const pid = document.getElementById('Pid');
            const telephone = document.getElementById('Telephone');
            const address = document.getElementById('Address');
            const submitBtn = document.getElementById('submitBtn');
            const loader = document.getElementById('loader');

            // 简单的表单验证
            let isValid = true;
            if(!customerName.value.trim()) {
                showNotification('请输入客户姓名', false);
                isValid = false;
            }
            if(!validateIdCard(pid.value)) {
                showNotification('请输入有效的18位身份证号', false);
                isValid = false;
            }
            if(!validatePhone(telephone.value)) {
                showNotification('请输入有效的11位手机号码', false);
                isValid = false;
            }
            if(!address.value.trim()) {
                showNotification('请输入联系地址', false);
                isValid = false;
            }
            if(!document.getElementById('terms').checked) {
                showNotification('请同意银行服务条款', false);
                isValid = false;
            }

            if(!isValid) return;

            // 显示加载动画
            submitBtn.disabled = true;
            loader.style.display = 'inline-block';

            // 准备请求数据
            const requestData = {
                Pid: pid.value.trim().toUpperCase(),
                CustomerName: customerName.value.trim(),
                Telephone: telephone.value.trim(),
                Address: address.value.trim()
            };

            // 记录调试信息
            debugLog("准备发送请求到后端: http://localhost:8080/admin/user/signup");
            debugLog("请求方法: POST");
            debugLog("请求头: { 'Content-Type': 'application/json', 'accept': '*/*' }");
            debugLog(`请求数据: ${JSON.stringify(requestData)}`);

            try {
                // 发送请求到后端
                const response = await fetch('http://localhost:8080/admin/user/signup', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'accept': '*/*'
                    },
                    body: JSON.stringify(requestData)
                });

                // 记录响应信息
                const responseText = await response.text();
                debugLog(`响应状态: ${response.status}`);
                debugLog(`响应内容: ${responseText}`);

                if(response.ok) {
                    showNotification('注册成功！您的账户正在审核中', true);
                    // 清空表单
                    document.getElementById('registrationForm').reset();
                } else {
                    showNotification('注册失败: ' + (responseText || '未知错误'), false);
                }
            } catch (error) {
                console.error('注册错误:', error);
                debugLog('请求失败: ' + error.message);
                showNotification('网络错误: ' + error.message, false);
            } finally {
                // 重置按钮状态
                submitBtn.disabled = false;
                loader.style.display = 'none';
            }
        });

        // 实时验证身份证输入
        document.getElementById('Pid').addEventListener('input', function() {
            this.value = this.value.toUpperCase();
            if(this.value.length > 18) this.value = this.value.slice(0, 18);

            const isValid = validateIdCard(this.value);
            if(isValid) {
                this.style.borderColor = '#4CAF50';
            } else {
                this.style.borderColor = this.value ? '#f44336' : '#ddd';
            }
        });

        // 实时验证手机号输入
        document.getElementById('Telephone').addEventListener('input', function() {
            if(this.value.length > 11) this.value = this.value.slice(0, 11);

            const isValid = validatePhone(this.value);
            if(isValid) {
                this.style.borderColor = '#4CAF50';
            } else {
                this.style.borderColor = this.value ? '#f44336' : '#ddd';
            }
        });

        // 初始化调试信息
        debugLog("本调试控制台显示所有发送到后端API的请求信息");
        debugLog("请确保后端运行在 http://localhost:8080");
        debugLog("使用以下CURL命令测试接口: ");
        debugLog('curl -X \'POST\' \\\n  \'http://localhost:8080/admin/user/signup\' \\\n  -H \'accept: */*\' \\\n  -H \'Content-Type: application/json\' \\\n  -d \'{\n  "Pid": "111111111111111111",\n  "CustomerName": "示例姓名",\n  "Telephone": "13800138000",\n  "Address": "示例地址"\n}\'');
    </script>
</body>
</html>